import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../components/Login.vue'
import Home from '../components/Home.vue'
import Welcome from '../components/Welcome.vue'
import Users from '../components/user/Users.vue'
import Questions from '../components/question/Questions.vue'
import Test from '../components/test/Test.vue'
import AddTest from '../components/test/AddTest.vue'
import EditTest from '../components/test/EditTest.vue'
import Score from '../components/score/Score.vue'
import CheckScore from '../components/score/CheckScore.vue'
import Text from '../components/text/Text.vue'
import AddText from '../components/text/AddText.vue'
import EditText from '../components/text/EditText.vue'
import Check from '../components/check/Check.vue'
import CheckUser from '../components/check/CheckUser.vue'
import Comment from '../components/text/Comment.vue'
EditTest
Vue.use(VueRouter)

const routes = [

]

const router = new VueRouter({
    routes: [
        { path: '/', redirect: '/login' }, //重定向到登录页面
        { path: '/login', component: Login }, //登录页面
        {
            path: '/home',
            component: Home,
            redirect: '/Welcome',
            children: [
                { path: '/welcome', component: Welcome },
                { path: '/users', component: Users },
                { path: '/questions', component: Questions },
                { path: '/test', component: Test },
                { path: '/test/addtest', component: AddTest },
                { path: '/test/edittest', component: EditTest },
                { path: '/score', component: Score },
                { path: '/score/checkscore', component: CheckScore },
                { path: '/text', component: Text },
                { path: '/text/addtext', component: AddText },
                { path: '/text/edittext', component: EditText },
                { path: '/text/comment', component: Comment },
                { path: '/check', component: Check },
                { path: '/check/checkuser', component: CheckUser }
            ]
        }
    ]
})
//路由守卫
router.beforeEach((to, from, next) => {
    // to将要访问的路径，from从哪里来的路径
    if (to.path === '/login') return next();
    // 获取token
    const tokenStr = window.sessionStorage.getItem('token');
    if (!tokenStr) return next('/login');
    next();
})
export default router

